<template>
	<view>
		<template v-if="goodlist.length != 0">
			<view v-for="item in goodlist" class="ff">
				<view>
					<navigator :url="'/subpkg/shops/shops?goods_id='+item.goods_id">
						<image :src="item.goods_small_logo" mode=""></image>
					</navigator>
				</view>
				<view>
					<view>{{item.goods_name}}</view>
					<view>${{item.goods_price}}</view>
				</view>
			</view>
		</template>
		<template v-else>
			<view>暂无数据</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {
					// 查询关键词
					query: '项链',
					// 商品分类Id
					cid: '',
					// 页码值
					pagenum: 1,
					// 每页显示多少条数据
					pagesize: 10
				},
				goodlist:[],
				count:0,
				flag:true
			};
		},
		methods:{
			fun(){
				uni.request({
				    url: 'https://www.uinav.com/api/public/v1/goods/search', 
				    data: this.queryObj,
				    success: (res) => {
						console.log(res.data.message)
						this.count = res.data.message.total
						this.goodlist = [...this.goodlist,...res.data.message.goods]
						this.flag = true
				    }
				});
			},
		},
		onLoad(options) {
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.fun()
		},
		onReachBottom() {
			if(this.goodlist.length<this.count && this.flag){
				this.flag = false
				this.queryObj.pagenum++
				this.fun()
			}
		},
		onPullDownRefresh() {
			this.goodlist = []
			this.count = 0
			this.flag = true
			this.queryObj.pagenum = 1
			this.fun()
		}
	}
</script>

<style lang="scss">
	.ff{
		display: flex;
		justify-content: space-between;
	}
</style>
